import { format } from 'date-fns'

// 日期格式化
export function formatDate(date, fmt = 'yyyy-MM-dd HH:mm:ss') {
  if (!date) return ''
  return format(new Date(date), fmt)
}

// 获取快捷时间范围
export function getQuickTimeRange(type) {
  const now = new Date()
  let startTime = new Date()
  
  switch (type) {
    case 'today':
      startTime.setHours(0, 0, 0, 0)
      break
    case 'yesterday':
      startTime.setDate(now.getDate() - 1)
      startTime.setHours(0, 0, 0, 0)
      now.setDate(now.getDate() - 1)
      now.setHours(23, 59, 59, 999)
      break
    case 'last24hours':
      startTime.setHours(now.getHours() - 24)
      break
    case 'last7days':
      startTime.setDate(now.getDate() - 7)
      break
    case 'last30days':
      startTime.setDate(now.getDate() - 30)
      break
    default:
      startTime.setHours(now.getHours() - 24)
  }
  
  return {
    startTime: startTime.getTime(),
    endTime: now.getTime()
  }
}